module service.SystemConfigService;
import repository;
import std.conv : to;

class IdBlock {

  long nextId;
  long lastId;

  this(long nextId, long lastId) {
    this.nextId = nextId;
    this.lastId = lastId;
  }

  public long getNextId() {
    return nextId;
  }

  public long getLastId() {
    return lastId;
  }
}

class SystemConfigService {

	this() {
	}

  static IdBlock getNextId(long idBlockSize)
  {
      SystemConfigRepository repo = new SystemConfigRepository;
      string[string]  mp = repo.getAll();
      string old =  mp.get("next-dbid","");
      if(old.length == 0)
      {
          return null;
      }
      long oldValue = to!long(old);
      long newValue = oldValue + idBlockSize;
      repo.upDataId(to!string(newValue));
      return new IdBlock(oldValue, newValue - 1);
  }
}

